
var detailData;
var reportTable;
function getreportList() {
    if (typeof reportTable !== 'undefined') {
        reportTable.fnPageChange('first');
        return;
    }
    reportTable = $("#reportList").DataTable({
        "sAjaxSource": _path + "/report/queryByPage",     //服务端
        "fnServerParams": function (aoData) {               //ajax请求参数
            aoData.push(
                { "name": "webSite", "value": $("#webSite").val() },
                { "name": "status", "value": $("#status").val()||0 },
                { "name": "reason", "value": $("#reason").val()||0 },
                { "name": "sonReason", "value": $("#sonReason").val()||0 },
                { "name": "fromDate", "value": $("#fromDate").val() },
                { "name": "toDate", "value": $("#toDate").val() }
            );
        },
        "fnServerData": function(sUrl, aoData, fnCallback) {
            var data = new Array();
            for(var i in aoData)
                data.push(aoData[i].name + '=' + aoData[i].value);
            $.ajax( {
                "type": "POST",
                "url": sUrl,
                "dataType": "json",
                "data": data.join('&'),
                "success": function(resp) {
                    detailData = resp.dataList;
                    fnCallback(resp);
                }
            });
        },
        "sServerMethod": "POST",    //请求方式
        "sAjaxDataProp": "dataList",//后台返回数据名
        "aoColumns": [
            { "sTitle": "网址", "sWidth": "6%", mData: "website" },
            { "sTitle": "举报类型", "sWidth": "6%", "mData": "reason" },
            { "sTitle": "二级类型", "sWidth": "6%", "mData": "sonReason" },
            { "sTitle": "时间", "sWidth": "6%", "mData": "createTime" },
            { "sTitle": "qq", "sWidth": "6%", "mData": "qq" },
            { "sTitle": "电话", "sWidth": "6%", "mData": "telphone" },
            { "sTitle": "详细原因", "sWidth": "6%", "mData": "detailReason" },
            { "sTitle": "状态", "sWidth": "6%", "mData": function(data) {
                switch (data.status) {
                    case 0: return "待审核";
                    case 1: return "曝光";
                    case 2: return "已失效";
                }
            } },
            { "sTitle": "操作", "sWidth": "10%",
                "mData": function (data) {
                    var html = '';
                    html += '<a href="' + _path + '/report/delete/' + data.id + '" class="btn btn-xs red"><i class="fa fa-trash-o" title="删除"></i></a>';
                    html += '<a href="javascript:updateStatus(' + data.id + ',1)" class="btn btn-xs red"><i class="fa fa-check-square-o" title="曝光"></i></a>';
                    html += '<a href="javascript:updateStatus(' + data.id + ',2)" class="btn btn-xs red"><i class="fa fa-minus-square" title="失效"></i></a>';
                    return html;
                }
            }
        ]
    });
}

function updateStatus(id, status) {
    $.ajax({
        url: _path + '/report/updateStatus',
        data: {
            'id': id,
            'status': status
        },
        success: function(resp) {
            if(resp.statusCode === 200) {
                alert('修改成功！');
                window.location.reload();
            }
        }
    });
}